//
//  ViewController.m
//  AndonAutoCell
//
//  Created by 董文博 on 15/1/22.
//  Copyright (c) 2015年 OA. All rights reserved.
//

#import "AutoCellViewController.h"
#import "AutoCell.h"
#import <CoreText/CoreText.h>

@interface AutoCellViewController ()
@property(nonatomic,strong)NSMutableArray *datas;
@property(nonatomic,strong)NSMutableArray *tags;
@property(nonatomic,strong)NSMutableArray *heights;
@end

@implementation AutoCellViewController
-(NSMutableArray *)tags
{
    if (_tags == nil) {
        _tags = [[NSMutableArray alloc] init];
    }
    return _tags;
}

-(NSMutableArray *)heights
{
    if (_heights == nil) {
        _heights = [[NSMutableArray alloc] init];
    }
    return _heights;
}


-(NSMutableArray *)datas
{
    if (_datas == nil) {
        _datas = [[NSMutableArray alloc] initWithObjects:@"hdfosdfohsdofhosdf呵呵呵呵尼玛😄hdfosdfohsdofhosdf呵呵呵呵尼玛😄hdfosdfohsdofhosdf呵呵呵呵尼玛😄hdfosdfohsdofhosdf呵呵呵呵尼玛😄hdfosdfohsdofhosdf呵呵呵呵尼玛😄",@"从宏观嘎嘎嘎嘎嘎嘎哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈",@"别说话行吗",@"aaaaaaaaaaaaaaaaaaaaaaaaaa",@"dfsdfsadfasdfsadfasdfasdfasdfasdfasdfasdfasdfasssssssssssdfsadfasdfasdfakdhjsfashdlkfhjsoidufosdufosudofusodfuosdaufoi",@"和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和",@"dfsdfsadfasdfsadfasdfasdfasdfasdfasdfasdfasdfasssssssssssdfsadfasdfasdfakdhjsfashdlkfhjsoidufosdufosudofusodfuosdaufoi",@"和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和",@"dfsdfsadfasdfsadfasdfasdfasdfasdfasdfasdfasdfasssssssssssdfsadfasdfasdfakdhjsfashdlkfhjsoidufosdufosudofusodfuosdaufoi",@"和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和",@"dfsdfsadfasdfsadfasdfasdfasdfasdfasdfasdfasdfasssssssssssdfsadfasdfasdfakdhjsfashdlkfhjsoidufosdufosudofusodfuosdaufoi",@"和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和",@"dfsdfsadfasdfsadfasdfasdfasdfasdfasdfasdfasdfasssssssssssdfsadfasdfasdfakdhjsfashdlkfhjsoidufosdufosudofusodfuosdaufoi",@"和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和",@"hdfosdfohsdofhosdf呵呵呵呵尼玛😄hdfosdfohsdofhosdf呵呵呵呵尼玛😄hdfosdfohsdofhosdf呵呵呵呵尼玛😄hdfosdfohsdofhosdf呵呵呵呵尼玛😄hdfosdfohsdofhosdf呵呵呵呵尼玛😄",@"从宏观嘎嘎嘎嘎嘎嘎",@"别说话行吗",@"aaaaaaaaaaaaaaaaaaaaaaaaaa",@"dfsdfsadfasdfsadfasdfasdfasdfasdfasdfasdfasdfasssssssssssdfsadfasdfasdfakdhjsfashdlkfhjsoidufosdufosudofusodfuosdaufoi",@"和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和",@"dfsdfsadfasdfsadfasdfasdfasdfasdfasdfasdfasdfasssssssssssdfsadfasdfasdfakdhjsfashdlkfhjsoidufosdufosudofusodfuosdaufoi",@"和哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和",@"dfsdfsadfasdfsadfasdfasdfasdfasdfasdfasdfasdfasssssssssssdfsadfasdfasdfakdhjsfashdlkfhjsoidufosdufosudofusodfuosdaufoi",@"和哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和",@"dfsdfsadfasdfsadfasdfasdfasdfasdfasdfasdfasdfasssssssssssdfsadfasdfasdfakdhjsfashdlkfhjsoidufosdufosudofusodfuosdaufoi",@"和哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈和",@"dfsdfsadfasdfsadfasdfasdfasdfasdfasdfasdfasdfasssssssssssdfsadfasdfasdfakdhjsfashdlkfhjsoidufosdufosudofusodfuosdaufoi",@"和哈哈哈哈哈哈", nil];
    }
    return _datas;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tableView registerClass:[AutoCell class] forCellReuseIdentifier:@"autoCell"];
    //设置第一次的宽度
     self.heights = [AutoCell firstHeightWithData:self.datas width:self.view.frame.size.width*4/5];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.datas.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [self.heights[indexPath.row] doubleValue];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    AutoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"autoCell" forIndexPath:indexPath];
    if (cell == nil) {
        cell = [[AutoCell alloc] initWithStyle:(UITableViewCellStyleValue1) reuseIdentifier:@"autoCell"];
    }
    cell.titleLabel.text = @"你们搞的这个东西excited！";
    cell.contentLabel.text = self.datas[indexPath.row];
    [cell autoStartWith:indexPath tags:self.tags cellHeightClicked:^(CGFloat height) {
        self.heights[indexPath.row] = @(height);
        [self.tableView reloadData];
    }];
    return cell;
}


@end
